package cn.lg.soar.cloud.core.feign.fallback;

import cn.lg.soar.cloud.core.feign.OperationLogApiFeign;
import cn.lg.soar.common.model.LogDTO;
import cn.lg.soar.core.util.InnerSerializeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;

/**
 * 简单日志接口
 * @author luguoxiang
 * @date 2021-08-11
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.system.monitor.client.OperationLogApiClient")
public class OperationLogApiFallbackFactory implements FallbackFactory<OperationLogApiFeign> {
    protected static final Logger LOGGER = LoggerFactory.getLogger(OperationLogApiFallbackFactory.class);
    @Override
    public OperationLogApiFeign create(Throwable cause) {
        return new OperationLogApiFeign() {

            @Override
            public void saveLog(Collection<? extends LogDTO> logs) {
                LOGGER.error("saveLog：{}", InnerSerializeUtils.toJson(logs), cause);
            }

        };
    }
}
